package com.hongxun.modules.bss.controller;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hongxun.modules.api.entity.BDataDictionaryEntity;
import com.hongxun.modules.api.entity.BMaterialEntity;
import com.hongxun.modules.api.service.BDataDictionaryService;
import com.hongxun.modules.api.service.BMaterialService;
import com.hongxun.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongxun.modules.bss.entity.DMaterialModelEntity;
import com.hongxun.modules.bss.service.DMaterialModelService;
import com.hongxun.common.utils.PageUtils;
import com.hongxun.common.utils.Query;
import com.hongxun.common.utils.R;




/**
 * 	材料模块
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-11-02 15:23:03
 */
@RestController
@RequestMapping("/bss/dmaterialmodel")
public class DMaterialModelController extends AbstractController{
	@Autowired
	private DMaterialModelService dMaterialModelService;
	@Autowired
	private BDataDictionaryService bDataDictionaryService;

	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
        String wheres =" 1=1 ";
		if(query.get("mtype")!=null&&!query.get("mtype").toString().equals(""))
		{
			wheres+=" and  querytype = '" + query.get("mtype").toString()+"' ";
		}
		if(query.get("edition")!=null&&!query.get("edition").toString().equals(""))
		{
			wheres+=" and  queryedition = '" + query.get("edition").toString()+"' ";
		}
		if(query.get("mname")!=null&&!query.get("mname").toString().equals(""))
		{
			wheres+=" and  name like '%" + query.get("mname").toString()+"%' ";
		}
        query.put("filterSql",wheres+" ");
		List<DMaterialModelEntity> dMaterialModelList = dMaterialModelService.queryList(query);
		int total = dMaterialModelService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(dMaterialModelList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{guid}")
	public R info(@PathVariable("guid") String guid){
		DMaterialModelEntity dMaterialModel = dMaterialModelService.queryObject(guid);
		
		return R.ok().put("dMaterialModel", dMaterialModel);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
//	@RequiresPermissions("bss:dmaterialmodel:save")
	public R save(@RequestBody DMaterialModelEntity dMaterialModel){
		dMaterialModel.setCreateId(getUserId());
		dMaterialModel.setDatastate("新增");
		dMaterialModel.setQueryvoltage("全部");
		dMaterialModel.setQuerywire("全部");
		dMaterialModel.setQuerylinemin(BigDecimal.ZERO);
		dMaterialModel.setQuerylinemax(BigDecimal.ZERO);
		dMaterialModel.setQueryspanmin(BigDecimal.ZERO);
		dMaterialModel.setQueryspanmax(BigDecimal.ZERO);
		dMaterialModel.setQueryrod("全部");
		dMaterialModel.setQueryanglemin(BigDecimal.ZERO);
		dMaterialModel.setQueryanglemax(BigDecimal.ZERO);
		dMaterialModel.setQueryheight("全部");
		dMaterialModel.setQuerydiam("全部");
		dMaterialModel.setQuerycount("全部");
		dMaterialModel.setQuerybyqtype("全部");
		dMaterialModel.setQuerybyqrl("全部");
		dMaterialModel.setQuerybyqgz("全部");
		dMaterialModel.setQuerybyqcxs("全部");
		dMaterialModel.setQuerybyqylx("全部");
		dMaterialModel.setQueryqdbxfs("全部");
		dMaterialModel.setQueryqdtype("全部");
		dMaterialModel.setQuerytjkgfa("全部");
		dMaterialModel.setQuerytjkgzj("全部");
      dMaterialModelService.save(dMaterialModel);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody DMaterialModelEntity dMaterialModel){
		dMaterialModelService.update(dMaterialModel);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
   public R delete(@RequestBody String[] guids){
		dMaterialModelService.deleteBatch(guids);
		
		return R.ok();
   }





}
